package com.jinshan.edu.controller;


import com.jinshan.edu.entity.EduSubject;
import com.jinshan.edu.service.EduSubjectService;
import com.jinshan.response.RetVal;
import com.jinshan.response.SubjectVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * <p>
 * 课程科目 前端控制器
 * </p>
 *
 * @author Jinshan
 * @since 2020-06-24
 */
@RestController
@RequestMapping("/edu/subject")
@CrossOrigin
public class EduSubjectController {
    @Autowired
    private EduSubjectService eduSubjectService;

    @PostMapping("/upload")
    public RetVal upload(MultipartFile file) throws Exception {
        eduSubjectService.upload(file);
        return RetVal.success();
    }

    @GetMapping("/getAllSubject")
    public RetVal getAllSubject() {
        List<SubjectVO> subjectVOS = eduSubjectService.getAllSubject();
        return RetVal.success().data("subjectVOS", subjectVOS);
    }

    // @PostMapping("/addFirstLevelSubject")
    // public RetVal addFirstLevelSubject(EduSubject eduSubject) {
    //     boolean flag = eduSubjectService.addFirstLevelSubject(eduSubject);
    //     if (flag) {
    //         return RetVal.success();
    //     } else {
    //         return RetVal.error();
    //     }
    // }

    @PostMapping("/addSubject")
    public RetVal addSubject(EduSubject eduSubject) {
        boolean flag = eduSubjectService.addSubject(eduSubject);
        if (flag) {
            return RetVal.success();
        } else {
            return RetVal.error();
        }
    }

    @DeleteMapping("/{id}")
    public RetVal deleteSubject(@PathVariable("id") String id) {
        boolean flag = eduSubjectService.deleteSubjectById(id);
        if (flag) {
            return RetVal.success();
        } else {
            return RetVal.error();
        }
    }

    // @PostMapping("/addSecondLevelSubject")
    // public RetVal addFirstLevelSubject(EduSubject eduSubject) {
    //     boolean flag = eduSubjectService.addFirstLevelSubject(eduSubject);
    //     if (flag) {
    //         return RetVal.success();
    //     } else {
    //         return RetVal.error();
    //     }
    // }

}

